/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.io.Serializable;
import java.util.List;
import org.hibernate.*;
import pojo.Nhanvien;
import pojo.Phieuxuathang;
import util.HibernateUtil;

/**
 *
 * @author HoaDinhGiang
 */
public class phieuxuatDAO {
    public static List<Phieuxuathang> layDanhSachPhieuXuatTonTai(){
        List<Phieuxuathang> ds = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try{
            String hql = "select px from Phieuxuathang px where px.kichhoat = true order by px.maphieuxuathang ASC";
            Query query = session.createQuery(hql);
            ds = query.list();
        }catch(HibernateException ex){
            //Log the exception
            System.err.println(ex);
        }finally{
            session.close();
        }
        return ds;
    }
    public static boolean themPhieuXuat(Phieuxuathang nv){
        boolean flag = false;
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;
        try {
            transaction =  session.beginTransaction();
            Serializable save = session.save(nv);
            transaction.commit();
            flag = true;
        } catch (HibernateException ex) {
        //Log the exception
                        transaction.rollback();
            System.err.println(ex);
            
        } finally {
        session.close();
        }
        return flag;
    }
    public static boolean capNhatThongTinPhieuXuat(Phieuxuathang hh) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;
        try {
            transaction = session.beginTransaction();
            session.update(hh);
            transaction.commit();
        } catch (HibernateException ex) {
            //Log the exception
            transaction.rollback();
            System.err.println(ex);
        } finally {
            session.close();
        }
        return true;
}
}
